import java.util.Scanner;

public class Main{

    
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] left, right, line;
        String outString;
        while(sc.hasNext()){
            String str = sc.nextLine();
            //有王炸就王炸最大
            if(str.contains("joker JOKER")){
                outString = "joker JOKER";
            }else{
                //拆分成两手牌，再把每手牌拆开
                line = str.split("-");
                left = line[0].split(" ");
                right = line[1].split(" ");
                
                //炸弹是最大的,牌数相等的情况下比较两手牌最小的牌的大小
                if(left.length == 4 && right.length != 4){
                    outString = line[0];
                }else if(left.length != 4 && right.length ==4){
                    outString = line[1];
                }else if(left.length == right.length){
                    if(count(left[0]) > count(right[0])){
                        outString = line[0];
                    }else{
                        outString = line[1];
                    }
                }else{
                    outString = "ERROR";
                }
            }
            System.out.println(outString);
        }
    }
    
    //2-JOKER按大小返回2-16
    public static int count(String str){
        return "345678910JQKA2jokerJOKER".indexOf(str);
    }
}